<template>
	<div>
		<el-form ref="form" :model="form" label-width="80px">

		<el-form-item label="客户姓名" prop="userName">
			<el-input v-model="form.userName"></el-input>
		</el-form-item>
		<el-form-item label="性别" prop="sex">
			<el-select v-model="form.sex">
				<el-option v-for="(item,index) in sexData" :key="index" :value="item.value" :label="item.label"></el-option>
			</el-select>
		</el-form-item>
		<el-form-item label="年龄" prop="age">
			<el-input v-model="form.age"></el-input>
		</el-form-item>
		<el-form-item label="身份证号" prop="idNumber">
			<el-input v-model="form.idNumber"></el-input>
		</el-form-item>
		<el-form-item label="床位编号" prop="bedNumber">
			<el-select v-model="form.bedNumber">
				<el-option v-for="item in bedNums" :key="item.bedNum" :value="item.bedNum" :label="item.bedNum"></el-option>
			</el-select>
		</el-form-item>
		<el-form-item label="到期时间" prop="endTime">
			<el-date-picker v-model="form.endTime" format="yyyy-MM-dd HH:mm:ss" value-format="yyyy-MM-dd HH:mm:ss" :style="{width: '100%'}"
			 placeholder="请输入时间" clearable>
			</el-date-picker>
		</el-form-item>
		<el-form-item label="身体状况" prop="status">
			<el-input v-model="form.status"></el-input>
		</el-form-item>
		<el-form-item label="护理等级" prop="careGrade">
			<el-select v-model="form.careGrade">
				<el-option v-for="item in nurclass" :key="item.nclass" :value="item.nclass" :label="item.nclass"></el-option>
			</el-select>
		</el-form-item>
		<el-form-item label="医生" prop="doctor">
			<el-select v-model="form.doctor">
				<el-option v-for="item in doctors" :key="item.staffName" :value="item.staffName" :label="item.staffName"></el-option>
			</el-select>
		</el-form-item>		
		<el-form-item label="健康管家" prop="steward">
			<el-select v-model="form.steward">
				<el-option v-for="item in stewards" :key="item.staffName" :value="item.staffName" :label="item.staffName"></el-option>
			</el-select>
		</el-form-item>		
		<el-form-item label="护工" prop="carer">
			<el-select v-model="form.carer">
				<el-option v-for="item in carers" :key="item.staffName" :value="item.staffName" :label="item.staffName"></el-option>
			</el-select>
		</el-form-item>
		<el-form-item label="护士" prop="nurse">
			<el-select v-model="form.nurse">
				<el-option v-for="item in nurses" :key="item.staffName" :value="item.staffName" :label="item.staffName"></el-option>
			</el-select>
		</el-form-item>		
		<el-form-item label="备注" prop="note">
			<el-input v-model="form.note" type="textarea" :rows="3" placeholder="请输入备注"></el-input>
		</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="save">保存</el-button>
			</el-form-item>
		</el-form>

	</div>
</template>


<script>
	export default {
		name: 'UserEdit',
		components: {

		},
		props: [
			'showEdit',
			'userId',
			'editid',
			'recome'
		],
		data() {
			return {
				form: {
					userId: '',
					userName: '',
					sex: '',
					age: '',
					idNumber: '',
					bedNumber: null,
					fileNum: '',
					endTime: '',
					status: '',
					careGrade: null,
					doctor: null,
					steward: null,
					carer: null,
					nurse: null,
					note: ''

				},
				sexData: [{
					"label": "男",
					"value": "男"
				}, {
					"label": "女",
					"value": "女"
				}],
				// isupdate: false,
				url: '/user/add',
				bedNums: [],
				doctors: [],
				carers: [],
				nurses: [],
				nurclass: [],
				stewards: []
			}
		},
		created() {
			this.init()
			console.log("this.editid:" + this.editid)
			if (this.editid) {
				this.url ='/user/save'
				this.axios.get('/user/toedit', response => {
					console.log(response.obj);
					this.form.userId = response.obj.userId
					// console.log(this.form.id);
					this.form.userName = response.obj.userName
					this.form.sex = response.obj.sex
					this.form.age = response.obj.age
					this.form.idNumber = response.obj.idNumber
					this.form.bedNumber = response.obj.bedNumber
					this.form.fileNum = response.obj.fileNum
					this.form.endTime = response.obj.endTime
					this.form.status = response.obj.status
					this.form.careGrade = response.obj.careGrade
					this.form.doctor = response.obj.doctor
					this.form.steward = response.obj.steward
					this.form.carer = response.obj.carer
					this.form.nurse = response.obj.nurse
					this.form.note = response.obj.note
				}, {
					id: this.editid
				})
			}
			
			if(this.recome==1){
				this.url='/user/recovery'
			}
		},
		methods: {
			save() {
				this.$refs['form'].validate((valid) => {
					if (valid) {
						this.axios.post(this.url, response => {
							// 子组件要改变父组件的值
							this.$emit('update:show', false)
							this.$emit('getData')
						}, this.form)
					}
				})
			},
			init() {
				this.axios.get('/user/bed', response => {
					this.bedNums = response.obj
				})
				this.axios.get('/user/doctor', response => {
					this.doctors = response.obj
				})
				this.axios.get('/user/steward', response => {
					this.stewards = response.obj
				})
				this.axios.get('/user/carer', response => {
					this.carers = response.obj
				})
				this.axios.get('/user/nurse', response => {
					this.nurses = response.obj
				})
				this.axios.get('/user/nclass', response => {
					this.nurclass = response.obj
				})


			}
		}
	}
</script>

<style>
</style>
